package com.example.smartwaterapi.common.api;

/**
 * 错误码枚举
 * 错误码设计规则：
 * 1. 200xxx：成功相关
 * 2. 400xxx：客户端错误
 * 3. 401xxx：认证授权相关错误
 * 4. 403xxx：权限相关错误
 * 5. 404xxx：资源不存在
 * 6. 409xxx：业务冲突
 * 7. 500xxx：服务器内部错误
 * 
 * 具体模块错误码：
 * - 用户模块：1xxx
 * - 设备模块：2xxx
 * - 饮水记录模块：3xxx
 * - 文件模块：4xxx
 * - 微信模块：5xxx
 * - 表盘模块：6xxx
 * - 成就模块：7xxx
 * - 系统模块：9xxx
 */
public enum ErrorCode {

    // ========== 成功相关 ==========
    SUCCESS("200000", "操作成功"),
    
    // ========== 客户端错误 ==========
    BAD_REQUEST("400000", "请求参数错误"),
    PARAM_MISSING("400001", "缺少必要参数"),
    PARAM_TYPE_ERROR("400002", "参数类型错误"),
    PARAM_BIND_ERROR("400003", "参数绑定错误"),
    PARAM_VALID_ERROR("400004", "参数验证错误"),
    
    // ========== 认证授权相关错误 ==========
    UNAUTHORIZED("401000", "未授权，请先登录"),
    TOKEN_EXPIRED("401001", "登录已过期，请重新登录"),
    TOKEN_INVALID("401002", "无效的授权信息"),
    ACCOUNT_DISABLED("401003", "账号已被禁用"),
    ACCOUNT_LOCKED("401004", "账号已被锁定"),
    PASSWORD_ERROR("401005", "密码错误"),
    
    // ========== 权限相关错误 ==========
    FORBIDDEN("403000", "没有操作权限"),
    ACCESS_DENIED("403001", "访问被拒绝"),
    
    // ========== 资源不存在 ==========
    NOT_FOUND("404000", "请求资源不存在"),
    
    // ========== 业务冲突 ==========
    CONFLICT("409000", "资源冲突"),
    
    // ========== 服务器内部错误 ==========
    INTERNAL_ERROR("500000", "服务器内部错误"),
    SYSTEM_ERROR("500000", "系统错误"),
    SERVICE_UNAVAILABLE("500001", "服务不可用"),
    DATABASE_ERROR("500002", "数据库操作异常"),
    
    // ========== 用户模块错误 ==========
    USER_NOT_FOUND("401001", "用户不存在"),
    USER_ALREADY_EXISTS("409001", "用户已存在"),
    USER_REGISTER_FAILED("500001", "用户注册失败"),
    USER_UPDATE_FAILED("500002", "用户信息更新失败"),
    USER_DELETE_FAILED("500003", "用户删除失败"),
    
    // ========== 设备模块错误 ==========
    DEVICE_NOT_FOUND("404002", "设备不存在"),
    DEVICE_ALREADY_BOUND("409002", "设备已被绑定"),
    DEVICE_NOT_BOUND("400002", "设备未绑定"),
    DEVICE_OFFLINE("400003", "设备离线"),
    DEVICE_LOW_BATTERY("400004", "设备电量不足"),
    DEVICE_BINDING_FAILED("500004", "设备绑定失败"),
    DEVICE_UNBINDING_FAILED("500005", "设备解绑失败"),
    
    // ========== 饮水记录模块错误 ==========
    WATER_RECORD_NOT_FOUND("404003", "饮水记录不存在"),
    WATER_RECORD_ADD_FAILED("500006", "添加饮水记录失败"),
    WATER_RECORD_UPDATE_FAILED("500007", "更新饮水记录失败"),
    WATER_RECORD_DELETE_FAILED("500008", "删除饮水记录失败"),
    WATER_GOAL_INVALID("400005", "饮水目标设置无效"),
    
    // ========== 文件模块错误 ==========
    FILE_UPLOAD_FAILED("500009", "文件上传失败"),
    FILE_DELETE_FAILED("500010", "文件删除失败"),
    FILE_NOT_FOUND("404004", "文件不存在"),
    FILE_SIZE_EXCEEDED("400006", "文件大小超出限制"),
    FILE_TYPE_NOT_ALLOWED("400007", "文件类型不允许"),
    
    // ========== 微信模块错误 ==========
    WECHAT_LOGIN_FAILED("500011", "微信登录失败"),
    WECHAT_CODE_INVALID("400008", "微信授权码无效"),
    WECHAT_API_ERROR("500012", "微信API调用异常"),
    WECHAT_BIND_FAILED("500013", "微信绑定失败"),
    WECHAT_UNBIND_FAILED("500014", "微信解绑失败"),
    
    // ========== 表盘模块错误 ==========
    WATCHFACE_NOT_FOUND("404005", "表盘不存在"),
    WATCHFACE_UPLOAD_FAILED("500015", "表盘上传失败"),
    WATCHFACE_DELETE_FAILED("500016", "表盘删除失败"),
    WATCHFACE_UPDATE_FAILED("500017", "表盘更新失败"),
    WATCHFACE_INSTALL_FAILED("500018", "表盘安装失败"),
    
    // ========== 成就模块错误 ==========
    ACHIEVEMENT_NOT_FOUND("404006", "成就不存在"),
    ACHIEVEMENT_ALREADY_CLAIMED("409003", "成就已领取"),
    ACHIEVEMENT_CONDITION_NOT_MET("400009", "成就条件未满足"),
    ACHIEVEMENT_CLAIM_FAILED("500019", "成就领取失败"),
    
    // ========== 系统模块错误 ==========
    SYSTEM_CONFIG_ERROR("500020", "系统配置错误"),
    SYSTEM_BUSY("500021", "系统繁忙，请稍后再试"),
    RATE_LIMIT_EXCEEDED("429001", "请求过于频繁，请稍后再试");
    
    private final String code;
    private final String message;
    
    ErrorCode(String code, String message) {
        this.code = code;
        this.message = message;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getMessage() {
        return message;
    }
} 